package com.liuzy;

import java.util.Map;

import com.liuzy.util.AES;
import com.liuzy.util.RSA;

/**
 * 
 * @author liuzy
 * @version 2015年5月22日
 */
public class Test {

	public static void main(String[] args) throws Exception {
		System.out.println("--------------------");
		System.out.println("RSA");
		// Server
		Map<String, String> keyMap = RSA.createKey();
		String pubKey = keyMap.get("publicKey");
		String priKey = keyMap.get("privateKey");
		System.out.println("公钥:" + pubKey);
		System.out.println("私钥:" + priKey);

		// Client
		String msg = "username=刘仲阳&password=yjwkhhbj";
		System.out.println("原数据:" + msg);
		String mi = RSA.encode(msg, pubKey);
		System.out.println("加密后:" + mi);

		// Server
		String ming = RSA.decode(mi, priKey);
		System.out.println("解密后:" + ming);

		System.out.println("--------------------");
		System.out.println("AES");
		String mmg = "刘仲阳@163.com";
		String key = "sd54fs5d1f38sd1";
		System.out.println("原始消息:" + mmg);
		System.out.println("对称密钥:" + key);
		String encryptResult = AES.encrypt(mmg, key);
		System.out.println("加密后：" + AES.encrypt(mmg, key));
		String decryptResult = AES.decrypt(encryptResult, key);
		System.out.println("解密后：" + decryptResult);
	}

}
